package cn.detu.ln.controller;

import cn.detu.ln.entity.SelCourse;
import cn.detu.ln.service.SelCourseService;
import cn.detu.ln.utils.PageUtil;
import cn.detu.ln.utils.RestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/selcourse")
public class SelCourseController {
    @Autowired
    private SelCourseService selCourseService;
    // GET请求获取用户列表数据
    // localhost:1314/user/selectAll
    @GetMapping("{url}")
    public RestUtil userGet(@PathVariable String url, SelCourse course, PageUtil pageUtil, String search){
        switch (url){
            case "selectAll": return selCourseService.selectAll();
            case "courseDelete":return selCourseService.courseDelete(course.getCourseId());
            case "queryCourseByPage":return selCourseService.queryCourseByPage(pageUtil.getCurrent(),pageUtil.getRows(),
                    search);
            // 按课程性质模糊查询
            case "queryCourseByNaturePage":return selCourseService.queryCourseByNaturePage(pageUtil.getCurrent(),pageUtil.getRows(),
                    search);
            case "queryCourseByIdPage":return selCourseService.queryCourseByIdPage(pageUtil.getCurrent(),pageUtil.getRows(),
                    search);
        }

        return null;
    }
    @PostMapping("{url}")
    public RestUtil userPost(@PathVariable String url, SelCourse course){
        switch (url){
            case "courseUpdate":return selCourseService.courseUpdate(course);
            case "courseInsert":return selCourseService.courseInsert(course);
        }
        return null;
    }
    // GET请求根据userId获取单条数据
    // localhost:1315/course/queryCourseById/1001
    @GetMapping("queryCourseById/{courseId}")
    public SelCourse queryCourseById(@PathVariable("courseId") Integer courseId){
        return selCourseService.queryCourseById(courseId);
    }
}
